// field like summarymonthly

package df.bean.db.table;

import java.sql.ResultSet;
import java.sql.SQLException;

import df.bean.db.conn.DBConnection;
import df.bean.obj.util.DialogBox;
import df.bean.obj.util.JDate;
import df.bean.obj.util.Utils;
import df.bean.obj.util.Variables;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class PaymentMonthly extends SummaryMonthly {
    private Double exDrAmt = 0d;
    private Double exCrAmt = 0d;
    private Double ex400 = 0d;
    private Double ex401 = 0d;
    private Double ex402 = 0d;
    private Double ex406 = 0d;
    private Double gDrAmt = 0d;
    private Double gDr402 = 0d;
    private Double gDr406 = 0d;
    private Double gCrAmt = 0d;
    private Double abCrAmt = 0d;
    private Double abCr402 = 0d;
    private Double abCr406 = 0d;
    private double drNetTax406Amt = 0d;
    private Double salary = 0d;
    private Double positionAmt = 0d;
    
    private String tax406Date = "";
    private String paymentType = "";
    private String receiptChequeDate = "";
    static public String PAYMENT_TYPE_SALARY = "01";
    static public String PAYMENT_TYPE_DF = "04";
    public Statement statementForQuery = null;
    public Statement statementForQuerySalary = null;
    public Statement statementForInsert = null;
    public ResultSet resultSetForInsert = null;
    
    public PaymentMonthly(DBConnection conn) {
        super(conn);
        System.out.println("Process Payment : "+conn);
        try {
            this.setTableName("PAYMENT_MONTHLY");
//            this.setStatement(this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE));
            if (statementForQuery == null) statementForQuery = this.getDBConnection().getConnection().createStatement();
            if (statementForQuerySalary == null) statementForQuery = this.getDBConnection().getConnection().createStatement();
            if (statementForInsert == null) statementForInsert = this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        } catch (SQLException e) {
            // TODO
            System.out.print(e.getMessage());
        }
    }
    
    public void Destroy() {
        try {
            DialogBox.ShowWarning("Destroy");
            resultSetForInsert.close();
            statementForQuery.close();
            statementForQuerySalary.close();
            statementForInsert.close();
            resultSetForInsert = null;
            statementForQuerySalary = null;
            statementForQuery = null;
            statementForInsert = null;
        } catch (SQLException ex) {
            Logger.getLogger(PaymentMonthly.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Double getAbCr402() {
        return abCr402;
    }

    public void setAbCr402(Double abCr402) {
        this.abCr402 = abCr402;
    }

    public Double getAbCr406() {
        return abCr406;
    }

    public void setAbCr406(Double abCr406) {
        this.abCr406 = abCr406;
    }

    public Double getAbCrAmt() {
        return abCrAmt;
    }

    public void setAbCrAmt(Double abCrAmt) {
        this.abCrAmt = abCrAmt;
    }

    public Double getEx400() {
        return ex400;
    }

    public void setEx400(Double ex400) {
        this.ex400 = ex400;
    }

    public Double getEx401() {
        return ex401;
    }

    public void setEx401(Double ex401) {
        this.ex401 = ex401;
    }

    public Double getEx402() {
        return ex402;
    }

    public void setEx402(Double ex402) {
        this.ex402 = ex402;
    }

    public Double getEx406() {
        return ex406;
    }

    public void setEx406(Double ex406) {
        this.ex406 = ex406;
    }

    public Double getExCrAmt() {
        return exCrAmt;
    }

    public void setExCrAmt(Double exCrAmt) {
        this.exCrAmt = exCrAmt;
    }

    public Double getExDrAmt() {
        return exDrAmt;
    }

    public void setExDrAmt(Double exDrAmt) {
        this.exDrAmt = exDrAmt;
    }

    public Double getGCrAmt() {
        return gCrAmt;
    }

    public void setGCrAmt(Double gCrAmt) {
        this.gCrAmt = gCrAmt;
    }

    public Double getGDr402() {
        return gDr402;
    }

    public void setGDr402(Double gDr402) {
        this.gDr402 = gDr402;
    }

    public Double getGDr406() {
        return gDr406;
    }

    public void setGDr406(Double gDr406) {
        this.gDr406 = gDr406;
    }

    public Double getGDrAmt() {
        return gDrAmt;
    }

    public void setGDrAmt(Double gDrAmt) {
        this.gDrAmt = gDrAmt;
    }

    public double getDrNetTax406Amt() {
        return drNetTax406Amt;
    }

    public void setDrNetTax406Amt(double drNetTax406Amt) {
        this.drNetTax406Amt = drNetTax406Amt;
    }

    public String getTax406Date() {
        return tax406Date;
    }

    public void setTax406Date(String tax406Date) {
        this.tax406Date = tax406Date;
    }

    public double getPositionAmt() {
        return positionAmt;
    }

    public void setPositionAmt(Double positionAmt) {
        if (positionAmt == null) { positionAmt = 0d; }
        this.positionAmt = positionAmt;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        if (salary == null) { salary = 0d; }
        this.salary = salary;
    }

    public String getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(String paymentType) {
        this.paymentType = paymentType;
    }

    public String getReceiptChequeDate() {
        return receiptChequeDate;
    }

    public void setReceiptChequeDate(String receiptChequeDate) {
        this.receiptChequeDate = receiptChequeDate;
    }
    public int insertToPaymentSummmary(String hospitalCode) {
        String sql = "select * from VW_ALL_SUMMARY_MONTHLY where HOSPITAL_CODE='" + hospitalCode + "'";
        return insertToPaymentSummmaryBySQL(sql, "");
    }
    public int insertToPaymentSummmary(String hospitalCode, String doctorCode) {
        String sql = "select * from VW_ALL_SUMMARY_MONTHLY where HOSPITAL_CODE='" + hospitalCode + "' AND DOCTOR_CODE ='" + doctorCode + "'";
        return insertToPaymentSummmaryBySQL(sql, "");
    }
    public int insertToPaymentSummmary(String hospitalCode, String payDate, String doctorCode) {
        String sql = "select * from VW_ALL_SUMMARY_MONTHLY where HOSPITAL_CODE='" + hospitalCode + "' AND DOCTOR_CODE ='" + doctorCode + "'";
        return insertToPaymentSummmaryBySQL(sql, payDate);
    }
    
    private int insertToPaymentSummmaryBySQL(String sql, String payDate) {
        int ret = -1;
        ResultSet rs = null;
        try {
            if (statementForQuery == null) { statementForQuery = this.getDBConnection().getConnection().createStatement(); }
            rs = statementForQuery.executeQuery(sql);
            while (rs.next()) {
            	//System.out.println("Doctor Code In : "+rs.getString("DOCTOR_CODE"));
                this.setYyyy(rs.getString("YYYY"));
                this.setMm(rs.getString("MM"));
                this.setHospitalCode(rs.getString("HOSPITAL_CODE"));
                this.setDoctorCode(rs.getString("DOCTOR_CODE"));
                this.setTransactionDate(rs.getString("Transaction_Date"));
                this.setSumAmt(rs.getDouble("SUM_AMT"));
                this.setSumDiscAmt(rs.getDouble("Sum_Disc_Amt"));
                this.setSumPremiumAmt(rs.getDouble("Sum_Premium_Amt"));
                this.setSumPatientPaidAmt(rs.getDouble("Sum_Patient_Paid_Amt"));
                this.setDrSumAmt(rs.getDouble("DR_SUM_AMT"));
                this.setDrDiscAmt(rs.getDouble("DR_Disc_Amt"));
                this.setDrPremiumAmt(rs.getDouble("DR_Premium_Amt"));
                this.setDrCreditAmt(rs.getDouble("DR_Credit_Amt"));
                this.setDrDebitAmt(rs.getDouble("DR_Debit_Amt"));
//                this.setDrNetPaidAmt(rs.getDouble("DR_NET_PAID_AMT"));
                this.setDrTax400(rs.getDouble("DR_Tax_400"));
                this.setDrTax401(rs.getDouble("DR_Tax_401"));
                this.setDrTax402(rs.getDouble("DR_Tax_402"));
                this.setDrTax406(rs.getDouble("DR_TAX_406"));
                this.setHpSumAmt(rs.getDouble("HP_SUM_AMT"));
                this.setHpDiscAmt(rs.getDouble("HP_Disc_Amt"));
                this.setHpPremiumAmt(rs.getDouble("HP_Premium_Amt"));
                this.setHpTax(rs.getDouble("HP_TAX"));
                this.setUpdateDate(JDate.getDate());
                this.setUpdateTime(JDate.getDate());
                this.setUserID(rs.getString("USER_ID"));
                this.setGuarunteeAmt(rs.getDouble("Guaruntee_Amt"));
                this.setGuarunteeTax(rs.getDouble("Guaruntee_Tax"));
                this.setStatusModify(rs.getString("STATUS_MODIFY"));
                this.setBatchNo(rs.getString("BATCH_NO"));
                this.setOldDoctorCode(rs.getString("OLD_DOCTOR_CODE"));
//                this.setRemark( Utils.toThaiMoney(this.getDrNetPaidAmt()) );
                this.setPaymentModeCode(rs.getString("Payment_Mode_Code"));
                this.setRefPaidNo(rs.getString("Ref_Paid_No"));
                
                if (payDate.equals("")) {
                    this.setPayDate(rs.getString("PAY_DATE"));
                    this.setPaymentTermDate(rs.getString("Payment_Term_Date"));
                } else {
                    this.setPayDate(payDate);
                    this.setPaymentTermDate(payDate);
                }
                if (this.getPaymentModeCode().equals(PaymentMode.PAYMENT_CHEQUE)) {  this.setPayDate("");  } 
                
                
                this.setDrStepAmt(rs.getDouble("DR_Step_Amt"));
                this.setHpStepAmt(rs.getDouble("HP_Step_Amt"));
                this.setSumPremiumRecAmt(rs.getDouble("Sum_Premium_Rec_Amt"));
                this.setSumPayByCash(rs.getDouble("SUM_PAY_BY_CASH"));
                this.setSumPayByAR(rs.getDouble("SUM_PAY_BY_AR"));
                
                this.setCashAmt(rs.getDouble("CASH_AMT"));
                this.setCash400(rs.getDouble("CASH_400"));
                this.setCash401(rs.getDouble("CASH_401"));
                this.setCash402(rs.getDouble("CASH_402"));
                this.setCash406(rs.getDouble("CASH_406"));
                
                this.setArAmt(rs.getDouble("AR_AMT"));
                this.setAr400(rs.getDouble("AR_400"));
                this.setAr401(rs.getDouble("AR_401"));
                this.setAr402(rs.getDouble("AR_402"));
                this.setAr406(rs.getDouble("AR_406"));
                
                this.setExDrAmt(rs.getDouble("EXDR_AMT"));
                this.setExCrAmt(rs.getDouble("EXCR_AMT"));
                this.setEx400(rs.getDouble("EX_400"));
                this.setEx401(rs.getDouble("EX_401"));
                this.setEx402(rs.getDouble("EX_402"));
                this.setEx406(rs.getDouble("EX_406"));
                this.setGDrAmt(rs.getDouble("GDR_AMT"));
                this.setGDr402(rs.getDouble("GDR_402"));
                this.setGDr406(rs.getDouble("GDR_406"));
                this.setGCrAmt(rs.getDouble("GCR_AMT"));
                this.setAbCrAmt(rs.getDouble("ABCR_AMT"));
                this.setAbCr402(rs.getDouble("ABCR_402"));
                this.setAbCr406(rs.getDouble("ABCR_406"));    
                
                this.setSalary(rs.getDouble("SALARY"));
                this.setPositionAmt(rs.getDouble("POSITION_AMT"));
                if (this.getSalary() > 0) { this.setPositionAmt(0d); }  // check for get only POSITION_AMT > 0  //// DF + POSITION_AMT when SALARY = 0
                
                this.setPaymentType(PaymentMonthly.PAYMENT_TYPE_DF);
                
                //(DR_SUM_AMT-DR_PREMIUM_AMT+EXDR_AMT-EXCR_AMT+GDR_AMT-GCR_AMT+ABCR_AMT) 
                this.setDrNetPaidAmt(rs.getDouble("DR_SUM_AMT")
                        - rs.getDouble("DR_PREMIUM_AMT")
                        + rs.getDouble("EXDR_AMT")
                        - rs.getDouble("EXCR_AMT")
                        //+ rs.getDouble("GDR_AMT")
                        //- rs.getDouble("GCR_AMT")
                        + rs.getDouble("ABCR_AMT") );
                       // + this.getPositionAmt());  // เพิ่ม salary เนื่องจาก ให้ ค่าประจำตำแหน่ง จ่ายพร้อมค่า DF (DF + POSITION_AMT)
                this.setRemark( Utils.toThaiMoney(this.getDrNetPaidAmt()) );
                
                // CASH_406+AR_406+EX_406+GDR_406-ABCR_406
                this.setDrNetTax406Amt(rs.getDouble("CASH_406")
                                    + rs.getDouble("AR_406")
                                    + rs.getDouble("EX_406")
                                    //+ rs.getDouble("GDR_406")
                                    - rs.getDouble("ABCR_406"));
                // on case
                this.setTax406Date(this.getPayDate());
                
                // กรณี รับเช็คแล้วเกิดภาษีทันที (ควรจะมี table setup ว่าจะเกิดภาษีเมื่อไหร่)
                if (this.getPaymentModeCode().equals(PaymentMode.PAYMENT_CHEQUE)) { 
                    this.setReceiptChequeDate(this.getPaymentTermDate());   // วันที่รับเช็ค = วันที่จ่าย
                    this.setTax406Date(this.getReceiptChequeDate());    // วันที่เกิดภาษี = วันที่รับเช็ค
                }
                
                this.setIsHold(rs.getString("IS_HOLD")); 
                if (this.getIsHold().equals("Y")) { this.setPayDate(""); }

            	//System.out.println("Payment After Insert");
                if (!this.insert()) { 
                	//System.out.println("Can't Insert from payment");
                	return -1; 
                }else{
                	//System.out.println("Insert from payment");
                }
            }
            ret = ret + 1;
            
        } catch (SQLException e) {
        	System.out.println("Insert Payment Error : "+e);
            e.printStackTrace();
            TRN_Error.writeErrorLog(this.getDBConnection().getConnection(), TRN_Error.PROCESS_PAYMENT_MONTHLY,
                    "Transaction is duplicated", e.getMessage());
            ret = -1;
        }
            
        finally {
              try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
              }
              catch (SQLException ex)  {
                System.out.println("A SQLException error has occured in " + this.getClass().getName() + ".update() \n" + ex.getMessage());
                TRN_Error.writeErrorLog(this.getDBConnection().getConnection(), this.getClass().getName(), "Transaction was calculated", ex.getMessage());
                ex.printStackTrace();
                ret = -1;
              }
        }
        
        return ret;
    }
    
    public int insertToPaymentSummmaryForSalary(String hospitalCode, String payDate) {
        String sql = "select * from DOCTOR where HOSPITAL_CODE='" + hospitalCode + "' AND ACTIVE = '1'";
            //sql = sql + " AND (SALARY > 0)"; //if export payroll for salary only
            sql = sql + " AND (SALARY > 0 OR POSITION_AMT >0)"; //if export payroll for salary and position amount
            return insertToPaymentSummmaryForSalaryBySQL(sql, payDate);
    }
    public int insertToPaymentSummmaryForSalary(String hospitalCode, String payDate, String doctorCode) {
        String sql = "select * from DOCTOR where HOSPITAL_CODE='" + hospitalCode + "' AND ACTIVE = '1'";
            //sql = sql + " AND (SALARY > 0)"; //if export payroll for salary only
            sql = sql + " AND (SALARY > 0 OR POSITION_AMT >0)"; //if export payroll for salary and position amount
            sql = sql + " AND CODE = '" + doctorCode + "'";
            return insertToPaymentSummmaryForSalaryBySQL(sql, payDate);
    }
    
    public int insertToPaymentSummmaryForSalaryBySQL(String sql, String payDate) {
        int ret = -1;


        ResultSet rs = null;
//        Statement stmt = null;
        try {
            if (statementForQuerySalary == null) { statementForQuerySalary = this.getDBConnection().getConnection().createStatement(); }
            rs = statementForQuerySalary.executeQuery(sql); 
            
            while (rs.next()) {
                this.setYyyy(Batch.getYyyy());
                this.setMm(Batch.getMm());
                this.setHospitalCode(rs.getString("HOSPITAL_CODE"));
                this.setDoctorCode(rs.getString("CODE"));
                this.setTransactionDate(JDate.getDate());
                this.setSumAmt(0d);
                this.setSumDiscAmt(0d);
                this.setSumPremiumAmt(0d);
                this.setSumPatientPaidAmt(0d);
                this.setDrSumAmt(0d);
                this.setDrDiscAmt(0d);
                this.setDrPremiumAmt(0d);
                this.setDrCreditAmt(0d);
                this.setDrDebitAmt(0d);
                this.setDrTax400(0d);
                if(rs.getDouble("POSITION_AMT")>0 && rs.getDouble("SALARY")>0){
                    this.setDrTax401(rs.getDouble("SALARY")+rs.getDouble("POSITION_AMT"));
                    this.setDrTax402(0.00);
                }else{
                    this.setDrTax401(rs.getDouble("SALARY"));                    
                    this.setDrTax402(rs.getDouble("POSITION_AMT"));
                }
                this.setDrTax406(0d);
                this.setHpSumAmt(0d);
                this.setHpDiscAmt(0d);
                this.setHpPremiumAmt(0d);
                this.setHpTax(0d);
                this.setUpdateDate(JDate.getDate());
                this.setUpdateTime(JDate.getDate());
                this.setUserID(Variables.getUserID());
                this.setGuarunteeAmt(0d);
                this.setGuarunteeTax(0d);
                this.setStatusModify("");
//                this.setBatchNo(Batch.getBatchNo());
                this.setOldDoctorCode("CODE");
                this.setPaymentModeCode(rs.getString("PAYMENT_MODE_CODE"));
                this.setRefPaidNo(rs.getString("BANK_ACCOUNT_NO"));
                this.setPayDate(payDate);
                this.setReceiptChequeDate("");
                this.setPaymentTermDate(payDate);
                this.setDrStepAmt(0d);
                this.setHpStepAmt(0d);
                this.setSumPremiumRecAmt(0d);
                this.setSumPayByCash(0d);
                this.setSumPayByAR(0d);
                
                this.setCashAmt(0d);
                this.setCash400(0d);
                this.setCash401(0d);
                this.setCash402(0d);
                this.setCash406(0d);
                
                this.setArAmt(0d);
                this.setAr400(0d);
                this.setAr401(0d);
                this.setAr402(0d);
                this.setAr406(0d);
                
                this.setExDrAmt(0d);
                this.setExCrAmt(0d);
                this.setEx400(0d);
                this.setEx401(0d);
                this.setEx402(0d);
                this.setEx406(0d);
                this.setGDrAmt(0d);
                this.setGDr402(0d);
                this.setGDr406(0d);
                this.setGCrAmt(0d);
                this.setAbCrAmt(0d);
                this.setAbCr402(0d);
                this.setAbCr406(0d);
                this.setSalary(rs.getDouble("SALARY"));
                this.setPositionAmt(rs.getDouble("POSITION_AMT"));
                this.setPaymentType(PaymentMonthly.PAYMENT_TYPE_SALARY);
                
                this.setDrNetPaidAmt(this.getSalary() + this.getPositionAmt()); 
                this.setRemark( Utils.toThaiMoney(this.getDrNetPaidAmt()));
                
                this.setDrNetTax406Amt(0d);
                // on case
                this.setTax406Date("");
                
                this.setIsHold(rs.getString("IS_HOLD")); 
                if (this.getIsHold().equals("Y")) { this.setPayDate(""); }

                if (!this.insert()) { return -1; }
            }
            ret = ret + 1;
            
        } catch (SQLException e) {
            TRN_Error.writeErrorLog(this.getDBConnection().getConnection(), TRN_Error.PROCESS_SALARY_PAYMENT, 
                        "Insert salary data is fail. ", e.getMessage());
            e.printStackTrace();
            ret = -1;
        }
            
        finally {
              try {
                if (rs != null) {
                    rs.close();
                    rs = null;
                }
              }
              catch (SQLException ex)  {
                System.out.println("A SQLException error has occured in " + this.getClass().getName() + ".update() \n" + ex.getMessage());
                ex.printStackTrace();
                ret = -1;
              }
        }
        
        return ret;
    }
    
    @Override
    public boolean insert() {
        boolean ret = false;
        String sql = "select * from " + this.getTableName() + " where 0<>0";
        try {
            // Create an updatable result set
        	/*
            if (statementForInsert == null) {
                statementForInsert = this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
                resultSetForInsert = null;
            }
            if (resultSetForInsert == null) {
                resultSetForInsert = statementForInsert.executeQuery(sql);
            }
            */
            statementForInsert = this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            resultSetForInsert = statementForInsert.executeQuery(sql);
            // Move cursor to the "insert row"
            resultSetForInsert.moveToInsertRow();
            
            // Set values for the new row.
            resultSetForInsert.updateString("YYYY", this.getYyyy());
            resultSetForInsert.updateString("MM", this.getMm());
            resultSetForInsert.updateString("HOSPITAL_CODE", this.getHospitalCode());
            resultSetForInsert.updateString("DOCTOR_CODE", this.getDoctorCode());
            resultSetForInsert.updateString("Transaction_Date", this.getTransactionDate());
            resultSetForInsert.updateDouble("SUM_AMT", this.getSumAmt());
            resultSetForInsert.updateDouble("Sum_Disc_Amt", this.getSumDiscAmt());
            resultSetForInsert.updateDouble("Sum_Premium_Amt", this.getSumPremiumAmt());
            resultSetForInsert.updateDouble("Sum_Patient_Paid_Amt", this.getSumPatientPaidAmt());
            resultSetForInsert.updateDouble("DR_SUM_AMT", this.getDrSumAmt());
            resultSetForInsert.updateDouble("DR_Disc_Amt", this.getDrDiscAmt());
            resultSetForInsert.updateDouble("DR_Premium_Amt", this.getDrPremiumAmt());
            resultSetForInsert.updateDouble("DR_Credit_Amt", this.getDrCreditAmt());
            resultSetForInsert.updateDouble("DR_Debit_Amt", this.getDrDebitAmt());
            resultSetForInsert.updateDouble("DR_NET_PAID_AMT", this.getDrNetPaidAmt());
            resultSetForInsert.updateDouble("DR_NET_TAX_406_AMT", this.getDrNetTax406Amt());
            resultSetForInsert.updateDouble("DR_Tax_400", this.getDrTax400());
            resultSetForInsert.updateDouble("DR_Tax_401", this.getDrTax401());
            resultSetForInsert.updateDouble("DR_Tax_402", this.getDrTax402());
            resultSetForInsert.updateDouble("DR_TAX_406", this.getDrTax406());
            resultSetForInsert.updateDouble("HP_SUM_AMT", this.getHpSumAmt());
            resultSetForInsert.updateDouble("HP_Disc_Amt", this.getHpDiscAmt());
            resultSetForInsert.updateDouble("HP_Premium_Amt",this.getHpPremiumAmt());
            resultSetForInsert.updateDouble("HP_TAX", this.getHpTax());
            resultSetForInsert.updateString("UPDATE_DATE", this.getUpdateDate());
            resultSetForInsert.updateString("Update_Time", this.getUpdateTime());
            resultSetForInsert.updateString("USER_ID", this.getUserID());
            resultSetForInsert.updateDouble("Guaruntee_Amt", this.getGuarunteeAmt());
            resultSetForInsert.updateDouble("Guaruntee_Tax", this.getGuarunteeTax());
            resultSetForInsert.updateString("STATUS_MODIFY", this.getStatusModify());
            resultSetForInsert.updateString("BATCH_NO", this.getBatchNo());
            resultSetForInsert.updateString("OLD_DOCTOR_CODE", this.getDoctorCode());
            resultSetForInsert.updateString("Remark", this.getRemark());
            resultSetForInsert.updateString("Payment_Mode_Code", this.getPaymentModeCode());
            resultSetForInsert.updateString("Ref_Paid_No", this.getRefPaidNo());
            resultSetForInsert.updateString("PAY_DATE", this.getPayDate());
            resultSetForInsert.updateString("RECEIPT_CHEQUE_DATE", this.getReceiptChequeDate());
            resultSetForInsert.updateString("Payment_Term_Date", this.getPaymentTermDate());
            resultSetForInsert.updateDouble("DR_Step_Amt", this.getDrStepAmt());
            resultSetForInsert.updateDouble("HP_Step_Amt", this.getHpStepAmt());
            resultSetForInsert.updateDouble("Sum_Premium_Rec_Amt", this.getSumPremiumRecAmt());
            resultSetForInsert.updateDouble("SUM_PAY_BY_CASH", this.getSumPayByCash());
            resultSetForInsert.updateDouble("SUM_PAY_BY_AR", this.getSumPayByAR());
            
            resultSetForInsert.updateDouble("CASH_AMT", this.getCashAmt());
            resultSetForInsert.updateDouble("CASH_400", this.getCash400());
            resultSetForInsert.updateDouble("CASH_401", this.getCash401());
            resultSetForInsert.updateDouble("CASH_402", this.getCash402());
            resultSetForInsert.updateDouble("CASH_406", this.getCash406());
                
            resultSetForInsert.updateDouble("AR_AMT", this.getArAmt());
            resultSetForInsert.updateDouble("AR_400", this.getAr400());
            resultSetForInsert.updateDouble("AR_401", this.getAr401());
            resultSetForInsert.updateDouble("AR_402", this.getAr402());
            resultSetForInsert.updateDouble("AR_406", this.getAr406());
                
            resultSetForInsert.updateDouble("EXDR_AMT", this.getExDrAmt());
            resultSetForInsert.updateDouble("EXCR_AMT", this.getExCrAmt());
            resultSetForInsert.updateDouble("EX_400", this.getEx400());
            resultSetForInsert.updateDouble("EX_401", this.getEx401());
            resultSetForInsert.updateDouble("EX_402", this.getEx402());
            resultSetForInsert.updateDouble("EX_406", this.getEx406());
            resultSetForInsert.updateDouble("GDR_AMT", this.getGDrAmt());
            resultSetForInsert.updateDouble("GDR_402", this.getGDr402());
            resultSetForInsert.updateDouble("GDR_406", this.getGDr406());
            resultSetForInsert.updateDouble("GCR_AMT", this.getGCrAmt());
            resultSetForInsert.updateDouble("ABCR_AMT", this.getAbCrAmt());
            resultSetForInsert.updateDouble("ABCR_402", this.getAbCr402());
            resultSetForInsert.updateDouble("ABCR_406", this.getAbCr406());
            
            resultSetForInsert.updateString("TAX_406_DATE", this.getTax406Date());
            resultSetForInsert.updateString("IS_HOLD", this.getIsHold());
            resultSetForInsert.updateDouble("SALARY", this.getSalary());
            resultSetForInsert.updateDouble("POSITION_AMT", this.getPositionAmt());
            resultSetForInsert.updateString("PAYMENT_TYPE", this.getPaymentType());
            
            // Insert the row
            resultSetForInsert.insertRow();
            ret=true;
        } catch (SQLException e) {
            System.out.println("Insert : "+e);
            e.printStackTrace();
            TRN_Error.writeErrorLog(this.getDBConnection().getConnection(), this.getClass().getName(), "Transaction was duplicated", e.getMessage());
        }
        finally {        }
        return ret;
    }
    
    // roll back
    public boolean rollBackDelete(String hospitalCode, String yyyy, String mm, String paymentType) {
        List sqlCommand = new ArrayList();
        boolean ret = false;
        String sql1 = "delete from " + this.getTableName() + " WHERE YYYY='" + yyyy + "'"
                + " AND MM = '" + mm + "'"
                + " and HOSPITAL_CODE = '" + hospitalCode + "'"
                + " and PAYMENT_TYPE = '" + paymentType + "'"
                + " and (BATCH_NO IS NULL OR BATCH_NO = '')";
        sqlCommand.add( sql1 );
        ret = super.rollBack(sqlCommand);
        return ret;
    }
}
